<?php
namespace app\common\model;
use think\Model;
use think\model\concern\SoftDelete;


class Uploads extends Model
{
    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = 0;
    protected $autoWriteTimestamp = true;
    
    protected function base($query)
    {

    }

    protected function getTypeAttr($value)
    {
        $status = ['本地','阿里云'];
        return $status[$value];
    }
    public function getFilesizeAttr($value)
    {
        return format_bytes($value);
    }
    public static function UploadValidate($file) {
        $upload_image = System::get_config_by_code('oss');
        // dump($upload_image);exit;
        if ($upload_image['is_thumb'] == 1 || $upload_image['is_water'] == 1) {
            $object_image = \think\Image::open($file->getPathName());
            // 图片压缩
            if ($upload_image['is_thumb'] == 1) {
                $object_image->thumb($upload_image['max_width'], $upload_image['max_height']);
            }
            // 图片水印
            if ($upload_image['is_water'] == 1) {
                $object_image->water($upload_image['water_source'],9, 50);//添加水印
            }
            $object_image->save($file->getPathName());
        }
        return $file;
    }
}